home *** CD-ROM | disk | FTP | other *** search
/ Knitting Made Easy / Knitting.iso / App / Patterns.dxr / behaviors_35_Jump to Marker Button.ls < prev    next >
Encoding:
Text File  |  2002-04-18  |  7.4 KB  |  166 lines

  1. property myMarker, myJumpMode, myReturn
  2.  
  3. on getBehaviorDescription
  4.   return "JUMP TO MARKER BUTTON" & RETURN & RETURN & "A click on the sprite makes the playback head jump to a chosen marker in the same movie.  You can choose between:" & RETURN & "-> previous marker" & RETURN & "-> next marker" & RETURN & "-> any named marker in the movie" & RETURN & RETURN & "If more than one marker has the same name as the chosen marker, the playback head will jump to the first marker with that name in the movie.  If you need to use duplicate names, try adding a different number of spaces at the end of each, so that they  appear the same but are in fact different." & RETURN & RETURN & "This behavior is designed for use with the 'Jump Back Button'.  You can set it to record the frame number of the current marker so that the 'Jump Back Button' can subsequently return.  NOTE: This feature relies on a global variable: gNavigationButtonList." & RETURN & RETURN & "Use the 'Jump to Movie Button' behavior to jump to a marker in a different movie." & RETURN & RETURN & "PERMITTED MEMBER TYPES" & RETURN & "Graphic members" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Jump to marker in this movie" & RETURN & "* 'Go to' or 'Play and return'?" & RETURN & "* Remember current marker for Back button" & RETURN & RETURN & "Select 'Remember current marker for Back button' to ensure that the behavior 'remembers' which markers have already been visited." & RETURN & RETURN & "Use the associated 'Jump Back Button' behavior on a separate sprite to return to visited markers in reverse order." & RETURN & RETURN & "ASSOCIATED BEHAVIORS:" & RETURN & "+ Jump to Movie button" & RETURN & "+ Jump Back Button" & RETURN & "+ Jump Forward Button" & RETURN & "+ Push Button (to alter rollover / mouseDown states)"
  5. end
  6.  
  7. on getBehaviorTooltip
  8.   return "Use with graphic members." & RETURN & RETURN & "When you drop this behavior on a sprite," & RETURN & "you will be invited to choose which marker" & RETURN & "in the current movie to jump to on mouseUp." & RETURN & "You can also choose 'previous' or 'next'." & RETURN & RETURN & "Use this behavior with the 'Jump Back Button'" & RETURN & "to allow the user to return to visited" & RETURN & "sequences."
  9. end
  10.  
  11. on beginSprite me
  12.   Initialize(me)
  13. end
  14.  
  15. on mouseUp me
  16.   jump(me)
  17. end
  18.  
  19. on Initialize me
  20.   global gNavigationButtonList
  21.   if not getPos([#next, #previous, #loop], myMarker) then
  22.     theMarkerList = RETURN & the labelList
  23.     markerExists = offset(RETURN & myMarker & RETURN, theMarkerList)
  24.     if not markerExists then
  25.       ErrorAlert(me, #markerMissing, myMarker)
  26.     else
  27.       delete char 1 to markerExists of theMarkerList
  28.       if offset(RETURN & myMarker & RETURN, theMarkerList) then
  29.         ErrorAlert(me, #runtime_DuplicateMarkers, myMarker)
  30.       end if
  31.     end if
  32.   end if
  33.   if myReturn then
  34.     if voidp(gNavigationButtonList) then
  35.       gNavigationButtonList = [#stack: [], #forward: [], #index: []]
  36.     else
  37.       if gNavigationButtonList.ilk <> #propList then
  38.         ErrorAlert(me, #invalidGlobal, gNavigationButtonList)
  39.       else
  40.         if not gNavigationButtonList.findPos(#stack) then
  41.           ErrorAlert(me, #invalidGlobal, gNavigationButtonList)
  42.         else
  43.           if not gNavigationButtonList.findPos(#index) then
  44.             ErrorAlert(me, #invalidGlobal, gNavigationButtonList)
  45.           else
  46.             if not gNavigationButtonList.findPos(#forward) then
  47.               ErrorAlert(me, #invalidGlobal, gNavigationButtonList)
  48.             end if
  49.           end if
  50.         end if
  51.       end if
  52.     end if
  53.   end if
  54. end
  55.  
  56. on jump me
  57.   global gNavigationButtonList
  58.   case myMarker of
  59.     #previous:
  60.       targetIsNewMarker = marker(-(the maxinteger) / 2) <> marker(0)
  61.     #loop:
  62.       targetIsNewMarker = 0
  63.     #next:
  64.       targetIsNewMarker = marker(0) <> marker(the maxinteger / 2)
  65.     otherwise:
  66.       targetIsNewMarker = marker(0) <> marker(myMarker)
  67.   end case
  68.   if myReturn and targetIsNewMarker then
  69.     currentMarker = [#frame: marker(0), #movie: the movieName]
  70.     gNavigationButtonList.stack.append(currentMarker)
  71.     if not gNavigationButtonList.index.getPos(currentMarker) then
  72.       gNavigationButtonList.index.append(currentMarker)
  73.     end if
  74.     gNavigationButtonList.forward = []
  75.   end if
  76.   if myJumpMode = "Go to" then
  77.     case myMarker of
  78.       #previous:
  79.         go(#previous)
  80.       #loop:
  81.         go(#loop)
  82.       #next:
  83.         go(#next)
  84.       otherwise:
  85.         go(marker(myMarker))
  86.     end case
  87.   else
  88.     case myMarker of
  89.       #previous:
  90.         play frame marker(-1)
  91.       #loop:
  92.         play frame marker(0)
  93.       #next:
  94.         play frame marker(1)
  95.       otherwise:
  96.         play frame myMarker
  97.     end case
  98.   end if
  99. end
  100.  
  101. on ErrorAlert me, theError, Data
  102.   behaviorName = string(me)
  103.   delete word 1 of behaviorName
  104.   delete char -30001 of behaviorName
  105.   delete char -30001 of behaviorName
  106.   case Data.ilk of
  107.     #void:
  108.       Data = "<void>"
  109.     #symbol:
  110.       Data = "#" & Data
  111.   end case
  112.   case theError of
  113.     #getPDL_DuplicateMarkers:
  114.       alert("Two or more markers in this movie have the same name.  This could lead to confusion if you use this behavior to go to a named marker." & RETURN & RETURN & "Duplicate marker(s) = " & Data)
  115.     #markerMissing:
  116.       if the runMode = "Author" then
  117.         alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & "Behavior " & behaviorName & RETURN & RETURN & "The chosen marker no longer exists.  Choose a valid marker in the Behavior Parmeters dialog." & RETURN & RETURN & "Current marker = " & Data)
  118.       end if
  119.       abort()
  120.     #runtime_DuplicateMarkers:
  121.       if the runMode = "Author" then
  122.         alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & "Behavior " & behaviorName & RETURN & RETURN & "The chosen marker does not  have a unique name.  The playback head will jump to the first marker with this name:" & RETURN & RETURN & "Duplicate marker name = " & Data)
  123.       end if
  124.     #invalidGlobal:
  125.       alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & "Behavior " & behaviorName & RETURN & RETURN & "Behavior " & behaviorName & " requires a global gNavigationButtonList with the structure:" & RETURN & "[#stack [...], #index: [...], #forward: [...]]" & RETURN & RETURN & "Current value = " & Data)
  126.       halt()
  127.   end case
  128. end
  129.  
  130. on getPropertyDescriptionList me
  131.   if not (the currentSpriteNum) then
  132.     exit
  133.   end if
  134.   currentMember = sprite(the currentSpriteNum).member
  135.   markersList = GetMarkers(me)
  136.   if markersList.count() = 2 then
  137.     ErrorAlert(me, #getPDL_DuplicateMarkers, markersList[2])
  138.   end if
  139.   return [#myMarker: [#comment: "On mouseUp, jump to marker:", #format: #marker, #default: #next], #myJumpMode: [#comment: "Jump Mode:", #format: #string, #range: ["Go to", "Play and Return"], #default: "Go to"], #myReturn: [#comment: "Remember current marker for Back button?", #format: #boolean, #default: 1]]
  140. end
  141.  
  142. on GetMarkers me
  143.   localMarkerList = []
  144.   duplicatesList = []
  145.   markerString = the labelList
  146.   delete char -30000 of markerString
  147.   markerCount = the number of lines in markerString
  148.   i = 1
  149.   repeat while i <= markerCount
  150.     theMarker = markerString.line[i]
  151.     if localMarkerList.getPos(theMarker) then
  152.       if not duplicatesList.getPos(theMarker) then
  153.         duplicatesList.append(theMarker)
  154.       end if
  155.     else
  156.       localMarkerList.append(theMarker)
  157.     end if
  158.     i = 1 + i
  159.   end repeat
  160.   if duplicatesList.count() then
  161.     return [localMarkerList, duplicatesList]
  162.   else
  163.     return [localMarkerList]
  164.   end if
  165. end
  166.